package com.siyue.service;

import cn.hutool.json.JSONUtil;
import com.siyue.dto.WebCallDto;
import com.siyue.handler.SharedData;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.util.concurrent.ConcurrentHashMap;

@Service
@Slf4j
public class CallService {
   // @Resource
   // MyWebSocketClient myWebSocketClient;

    /**
     * 推送
     * @param token
     * @param id 拨号id
     * @param name 姓名
     * @param mobile 手机号
     */
    public void call(String token,int id, String name, String mobile) throws Exception{
        WebCallDto webCallDto = WebCallDto.builder().id(id).token(token).name(name).mobile(mobile).action("make_call").build();
        //myWebSocketClient.getSession().getAsyncRemote().sendText(JSONUtil.toJsonStr(webCallDto));
        SharedData.sessionMap.get(webCallDto.getToken()).sendMessage(new TextMessage(JSONUtil.toJsonStr(webCallDto)));
    }
}
